package top.jiangqiang.qyblog.admin.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;
import top.jiangqiang.qyblog.common.base.controller.BaseController;
import top.jiangqiang.qyblog.common.base.query.PageResult;
import top.jiangqiang.qyblog.common.base.response.Result;
import top.jiangqiang.qyblog.common.constant.RequestURLConstants;
import top.jiangqiang.qyblog.core.domain.dto.DraftQueryDto;
import top.jiangqiang.qyblog.core.domain.dto.DraftSaveOrUpdateDto;
import top.jiangqiang.qyblog.core.domain.vo.DraftVo;
import top.jiangqiang.qyblog.core.service.IDraftService;

/**
 * @author jiangqiang
 * @date 2022-12-03
 */
@RequiredArgsConstructor
@RestController
@RequestMapping(RequestURLConstants.DRAFT_CONTROLLER_PREFIX)
@Tag(name = "草稿接口")
public class DraftController extends BaseController {
    private final IDraftService draftService;

    @GetMapping
    @Operation(summary = "根据条件查询草稿列表", description = "查询草稿列表")
    public Result<PageResult<DraftVo>> list(@ParameterObject DraftQueryDto draftQueryDto) {
        return Result.ok(draftService.findByCondition(draftQueryDto));
    }

    @GetMapping("/{id}")
    @Operation(summary = "查询草稿详情", description = "查询草稿详情")
    public Result<DraftVo> get(@PathVariable Long id) {
        return draftService.getDraftById(id);
    }

    @PostMapping("/saveOrUpdate")
    @Operation(summary = "新增或编辑草稿", description = "新增或编辑草稿")
    public Result<DraftVo> saveOrUpdate(@RequestBody DraftSaveOrUpdateDto draftSaveOrUpdateDto) {
        return draftService.saveOrUpdateDraft(draftSaveOrUpdateDto);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除草稿", description = "根据id删除草稿")
    @Deprecated
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.ok(draftService.deleteDraftById(id));
    }

}
